﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <qsplitter.h>
#include "marketselfwidget.h"
#include "marketcomexch.h"
#include "controlwidget.h"
#include "mainorderwidget.h"
#include "popmktcombineexch.h"
#include <QTabWidget>
#include "mainpreentrustwidget.h"
#include "mainconditionwidget.h"
#include "maincombineentrustwidget.h"
#include "mainbalancewidget.h"
#include "mainholdwidget.h"
#include "mainentrustqueryhiswidget.h"
#include "mainbusinessqueryhiswidget.h"
#include "maincontractwidget.h"
#include "mainaverageentrustwidget.h"
#include <QAction>
#include "mainpopdialog.h"
#include "ui_mainpopdialog.h"
#include "selfmarketdialog.h"
#include "ui_selfmarketdialog.h"
#include "popmktcombineexchdialog.h"
#include "ui_popmktcombineexchdialog.h"
#include "combineexchdialog.h"
#include "ui_combineexchdialog.h"
#include "combineorderdialog.h"
#include "ui_combineorderdialog.h"
#include "defaultorderdialog.h"
#include "ui_defaultorderdialog.h"
#include "quickorderdialog.h"
#include "ui_quickorderdialog.h"
#include <QSettings>
#include <QMap>
#include "CommUtil/common.h"
#include "combinecontroldialog.h"
#include<QFile>
#include"ordersetterdlg.h"
#include<QDockWidget>
#include"settlementinfodialog.h"

using namespace std;

namespace Ui {
class MainWindow;
}
//int WINAPI OnReceiveMsg (void* szBuffer, int nType, int iLen);

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    //MainWindow();
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void createMenus();
    void createActions();
    void keyPressEvent ( QKeyEvent * k );
    void closeEvent(QCloseEvent *event);

    //void ShowInstrumentMarginRateInfo(IF2UnPacker *lpUnPacker);

    ///报单通知
    void OnRtnOrder(CThostFtdcOrderField *pOrder);
    ///成交通知
    void OnRtnTrade(CThostFtdcTradeField *pTrade);

	///交易服务器登录
	void OnUserLogin(int iRetID, QString errInfo,QString username);
    void OnRspQryInstrument(CThostFtdcInstrumentField *pInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
    ///投资者结算结果确认响应
    void OnRspSettlementInfoConfirm(QString ConfirmDateTime);

    ///请求查询投资者结算结果响应
    void OnRspQrySettlementInfo(CThostFtdcSettlementInfoField *pSettlementInfo, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
    void OnRspQryTradingAccount(CThostFtdcTradingAccountField *pTradingAccount, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
    void OnDepthMarketData(CThostFtdcDepthMarketDataField *pDepthMarketData);
    ///查询持仓响应
    void OnRspQryInvestorPosition(CThostFtdcInvestorPositionField *pInvestorPosition, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	void ShowStatusTip(QString msg);
    ///请求查询成交响应
    void OnRspQryTrade(CThostFtdcTradeField *pTrade);

    void ReqQryInstrumentMarginRate(QString code);

    void OnRspQryInstrumentMarginRate(CThostFtdcInstrumentMarginRateField *pInstrumentMarginRate);

signals:
    void SigSetStatusTip(QString str);
    void SigRaiseOrderDockWidget();
    void SigShowSettlementInfoDialog();

public slots:
    void SlotdockLocationChanged(int index);
    void SlotdockLocationChanged1(Qt::DockWidgetArea);
    void SlotdockLocationChanged2(Qt::DockWidgetArea);
    void SlotdockLocationChanged3(Qt::DockWidgetArea);
    void SlotdockLocationChanged4(Qt::DockWidgetArea);
    void SlotdockLocationChanged5(Qt::DockWidgetArea);
    void SlotdockLocationChanged6(Qt::DockWidgetArea);
    void SlotdockLocationChanged7(Qt::DockWidgetArea);

    //交易者结算单确认
    void SlotShowSettlementInfoDialog();
    void SlotGetOpenRatio(char bs,QString ordertype,QString futucode,double price);
    ///撤单
    void SlotCancelOrder(TThostFtdcExchangeIDType& ExchangeID, TThostFtdcOrderSysIDType& entrust_no,int CancelType);
    /// 改单
    void SlotChangeOrder();

    ///平所持持仓
    void SlotClosePositon(QString exch_type,QString contract_code, char c_bs, char c_direction, char c_hedge,int real_enable_amount,int enable_amount);
    void OrderInsert(const char* exch_type, const char* contract_code, char c_bs, char c_direction, char c_hedge, int l_entrust_amount, double en_entrust_price);
    void SlotOrderInsert(FastInfo* pFastInfo);
    void SlotkeyPressEvent ( QKeyEvent * k );
    void OrderSetterDlgShow();
    void MainPopDlgShow();
    void destroyWin();
    void exit();
private:
    OrderSetterDlg* m_pOrderSetterDlg;

	long							m_lInstrumentCount;

    QSplitter*						mainSplitter,*vSplitter,*hSplitter;
    QTabWidget*						tabWidget,*tabWidget2;
    MarketSelfWidget*				marketselfwidget;
    MarketComexch*					marketcomexch;
    PopMktCombineExch*				popmktcombineexch;
    ControlWidget*					controlwidget;//对应自选行情的控制模块
    CombineControlDialog*           m_CombineControlDlg;//对应自定义组合行情的控制模块
    MainOrderWidget*				mainorderwidget;
    MainPreEntrustWidget*			mainpreentrustwidget;
    MainConditionWidget*			mainconditionwidget;
    MainCombineEntrustWidget*		maincombineentrustwidget;
    MainBalanceWidget*				mainbalancewidget;
    MainHoldWidget*					mainholdwidget;
    MainEntrustQueryHisWidget*		mainentrustqueryhiswidget;
    MainBusinessQueryHisWidget*		mainbusinessqueryhiswidget;
    MainContractWidget*				maincontractwidget;
    MainAverageEntrustWidget*		mainaverageentrustwidget;
    SettlementInfoDialog*           m_SettlementInfoDialog;//客户结算单确认Dialog
    QMenu* fileMenu;//文件菜单
    QMenu* editMenu;//编辑菜单
    QMenu* helpMenu;//帮助菜单
    QMenu* formatMenu;

    QAction* m_pOrderSetterAction;
    QAction* newAct,* newAct1,* newAct2,* newAct3,* newAct4,* newAct5,* newAct6;//新建
    QAction* exitAct;//退出

    QAction* aboutAct1;//关于
    QLabel*  infoLabel;
    QDialog* m_MainPopDialog;
    QGridLayout* mainlayout;
    QHBoxLayout* buttonlayout;

    Ui::MainWindow  *ui;
};

#endif // MAINWINDOW_H
